package com.young.shop_admin.controller;

import com.young.shop_admin.pojo.entity.Goods;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 *  商品上架
 */
@WebServlet("/shelves")
public class GoodsShelvesController extends BaseController{
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        resp.setHeader("Access-Control-Allow-Origin","http://localhost:63342");
        //获取商品id
        Goods goods = convertParamsToEntity(req, Goods.class);
        Integer id = goods.getId();

        //通过id修改商品转态，调用service

        try {
            Goods soldOutGoods = goodsList.checkShelvesGoods(id);
            writerSuccessResult(soldOutGoods,resp);
        }catch (RuntimeException e) {
            String errorMsg = e.getMessage();
            writerErrorResult(errorMsg, resp);
        }

    }
}
